Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




update( ) FUNCTION


The 'update( )' Function is used to update an entry in the Dictionary using the 'Key'.


Note : The 'Key' won't be updated. Just the 'Value' associated to that 'Key' would be updated.

Example :


x = {
    5 : "Is a Number", 
    "John": "Is a Name", 
    "Python": "Is a Language"
}
x.update({5: "Is an one digit number"})
print(x)


Output :



  {5: 'Is an one digit number', 'John': 'Is a Name', 'Python': 'Is a Language'}

So, in the above code we have created a 'Dictionary' using braces '{ }' and 'Key' and 'Value' pairs.


x = {
    5 : "Is a Number", 
    "John": "Is a Name", 
    "Python": "Is a Language"
}

And initialised to the variable 'x'.


java_Collections

Now, we are supposed to update the value of the 'Key', '5' with 'Is an one digit number'.


So, we have used the below way to update it.


x.update({5: "Is an one digit number"})

And the entry for the 'Key' '5' is updated in the 'Dictionary'.


java_Collections

And we get the below output,


Output :



  {5: 'Is an one digit number', 'John': 'Is a Name', 'Python': 'Is a Language'}